package demo.database.MariaDB.D03_元数据;


import java.sql.DatabaseMetaData;

import javax.sql.DataSource;

import com.titan.core.utils.db.DataSourceUtils;
import com.titan.core.utils.db.JdbcUtils;
import com.titan.core.utils.debug.Timer;
import com.titan.core.web.utils.SpringBootUtils;
import com.titan.services.Container.v1.ContainerUtils;
import com.titan.services.Container.v1.JdbcV1Container.DatabaseMetaDataContainer;

import demo.database.MariaDB.utils.MariaDBUtils;

public class D03_获取数据库相关信息 {
    private static void run(final DatabaseMetaDataContainer meta) throws Exception {
        DatabaseMetaData dbmd = meta.getDatabaseMetaData();
        System.out.println("数据库已知的用户: "+ dbmd.getUserName());      
        System.out.println("数据库的系统函数的逗号分隔列表: "+ dbmd.getSystemFunctions());      
        System.out.println("数据库的时间和日期函数的逗号分隔列表: "+ dbmd.getTimeDateFunctions());      
        System.out.println("数据库的字符串函数的逗号分隔列表: "+ dbmd.getStringFunctions());      
        System.out.println("数据库供应商用于 'schema' 的首选术语: "+ dbmd.getSchemaTerm());      
        System.out.println("数据库URL: " + dbmd.getURL());      
        System.out.println("是否允许只读:" + dbmd.isReadOnly());      
        System.out.println("数据库的产品名称:" + dbmd.getDatabaseProductName());      
        System.out.println("数据库的版本:" + dbmd.getDatabaseProductVersion());      
        System.out.println("驱动程序的名称:" + dbmd.getDriverName());      
        System.out.println("驱动程序的版本:" + dbmd.getDriverVersion());
    }

    
    public static void main(String[] args) {
        Timer timer = Timer.$();
        DataSource datasource = MariaDBUtils.getDataSource();
        DatabaseMetaDataContainer container = null;
        try {
            JdbcUtils.setDataSource(datasource);
            container = JdbcUtils.getMetaDataDatabase("jdbc.DatabaseMetaData");
            container.startup();
            run(container);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ContainerUtils.shutdown(container);
            DataSourceUtils.close(datasource);
            SpringBootUtils.shutdown();
            timer.print();
        }
    }
}
